Skip to content

fix(echo): retain upstream advisories for Echo packages - #11652

Open
LaizaAngrest wants to merge 5 commits into
aquasecurity:mainfrom
LaizaAngrest:fix/echo-upstream-advisories
Open

LaizaAngrest wants to merge 5 commits into
aquasecurity:mainfrom
LaizaAngrest:fix/echo-upstream-advisories

Conversation

@LaizaAngrest

@LaizaAngrest LaizaAngrest commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Echo language packages were previously routed only to the echo-osv bucket. This meant unrelated upstream vulnerabilities disappeared as soon as a package version had an Echo suffix.

This PR keeps the upstream advisory set as the baseline for Echo packages and overlays Echo advisories on top:

  • load both upstream and Echo advisories for Echo package versions
  • let an Echo advisory replace an upstream advisory with the same primary vulnerability ID
  • compare Echo advisories against the full Echo version with the Echo comparer
  • compare remaining upstream advisories against the base version before +echo.N with the ecosystem's normal comparer
  • keep plain package versions, Seal packages, and Candidate routing unchanged

If no active Echo advisory exists for a vulnerability, the upstream advisory remains visible. This is the behavior discussed in #11621.

Version-scoped not_applicable records

The current Echo feed publishes version-scoped not_applicable decisions only as withdrawn records. trivy-db does not store withdrawn records, so there is no active Echo advisory to override the upstream one and a matching upstream finding remains visible. As discussed, those known non-applicable findings can be handled with VEX separately.

Testing

  • go test ./pkg/detector/library/...
  • go test -race ./pkg/detector/library/...
  • go vet ./pkg/detector/library/...
  • go test ./pkg/detector/...
  • golangci-lint run ./...
  • full Trivy binary build
  • go mod tidy with no go.mod or go.sum changes

The test matrix covers PyPI, Maven, npm, NuGet, and Go, including:

  • upstream fallback when the Echo bucket is empty
  • replacement by matching primary vulnerability ID
  • different primary IDs that share an alias
  • fixed and unfixed Echo advisories
  • Echo and upstream findings reported together
  • Maven inclusive upstream ranges such as <=1.2.3
  • metadata-aware Echo comparison and base-version upstream comparison
  • plain package versions

I also tested a fresh vulnerability DB end to end:

  • audited every active Echo fixed-version/package combination in the current feed; no unrelated upstream finding disappeared compared with the base version
  • known vulnerable Echo revisions were detected in all five ecosystems
  • their representative CVEs disappeared at the fixed Echo revisions
  • unrelated upstream findings remained (including 19 Go findings and 12 Python findings)
  • org.springframework:spring-webflux 5.3.39+echo.1 now reports upstream CVE-2026-22735 from the <=5.3.39 range
  • for golang.org/x/net, CVE-2023-45288 was removed for v0.22.0+echo.1, while unrelated upstream findings remained
  • CVE-2026-46600 correctly used the Echo advisory and Echo fixed version instead of the matching upstream advisory

Co-authored-by: Cursor <cursoragent@cursor.com>
@LaizaAngrest

LaizaAngrest commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@DmitriyLewen I opened this PR with the upstream-baseline + Echo-overlay approach we discussed. Echo advisories override matching primary vulnerability IDs and use the Echo comparer, while unrelated upstream advisories use the ecosystem comparer against the upstream base version. I added coverage for all five Echo language ecosystems and verified it against a fresh DB: fixed Echo CVEs disappeared while unrelated upstream findings remained. Could you please review it when you have time?

@LaizaAngrest LaizaAngrest changed the title fix(library): retain upstream advisories for Echo packages fix(echo): retain upstream advisories for Echo packages Nov 17, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

@DmitriyLewen Follow-up from a full fresh-DB audit: Maven inclusive upstream ranges such as <=5.3.39 exposed a comparison gap because Maven orders 5.3.39+echo.1 above 5.3.39. I fixed this by evaluating only upstream advisories against the base version, while Echo advisories still use the full Echo version and Echo comparer. I also moved the merge cases into TestDriver_Detect, added the Maven inclusive-range and mixed Echo/upstream cases, limited overrides to matching primary IDs, and documented the withdrawn not_applicable/VEX behavior. Re-running every active Echo fixed-version/package combination found no remaining unrelated upstream finding that disappears versus its base version.

@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

@DmitriyLewen I added an explicit regression test and documentation for the no-range behavior. The fixture now has a vulnerable upstream advisory and a matching active Echo advisory with no vulnerable or patched versions; TestDriver_Detect verifies that the Echo package is not reported.

The corresponding feed implementation is in https://github.com/buildecho/platform/pull/2215. It publishes only our supported language-package code_not_in_use decisions without ranges or versions; database_specific documents the reason but is not used by Trivy today. Other not_applicable reasons still fall back to upstream. A mixed-record test also verifies that an in_progress package is omitted rather than emitted with introduced: 0.

This intentionally relies on the active empty-range Echo advisory replacing the matching upstream advisory. Could you please double-check that this is the behavior you want us to rely on?

@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

Hi @DmitriyLewen, just a gentle reminder when you have time to review this PR. All CI checks are green. The main point we would appreciate your confirmation on is relying on an active Echo advisory without affected ranges to suppress the matching upstream advisory. Thanks!

@DmitriyLewen

Copy link
Copy Markdown
Contributor

Hi Laiza,

We have a release coming up soon, and right now we're busy with priority tasks for it.
I'll review this PR as soon as I have time.

As for your question about empty ranges: from the OSV point of view, a package without ranges and versions can be considered to have no affected versions (ossf/osv-schema#27).
This matches how the current Trivy code behaves.

However, for language packages we use more than just OSV, so we need some time to look at the other sources and decide what to do: make this behavior the default, mark vulnerabilities with statuses, or something else.

To give us more information for the discussion, could you please answer two questions:

  1. Could you share a sample record in the new format (for example, one of the code_not_in_use cases) so we can use it in the discussion? The current published feed doesn't contain such records yet.
  2. On November 15, you mentioned that a package-wide not_affected isn't safe because new Echo builds aren't re-triaged. Is code_not_in_use different in that respect, i.e. does it hold for every future build of the package?

We'll discuss it with the team and get back to you once we have a decision.

Regards, Dmitriy

@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

Hi Dmitriy,

Thanks — the empty-range interpretation is clear.

Here is a sample based on a current code_not_in_use case (ECHO-042f-77a6-c297 / CVE-2023-6378):

{
  "id": "ECHO-042f-77a6-c297",
  "upstream": ["CVE-2023-6378"],
  "affected": [
    {
      "package": {
        "ecosystem": "Echo:Maven",
        "name": "ch.qos.logback:logback-core",
        "purl": "pkg:maven/ch.qos.logback/logback-core"
      },
      "database_specific": {
        "status": "not_affected",
        "justification": "code_not_in_use"
      }
    }
  ]
}

The logback-classic package for the same vulnerability is still in_progress, so it is intentionally omitted from affected and falls back to upstream.

For the second question: no, code_not_in_use is not currently guaranteed to remain true for every future Echo build, because we do not re-triage every existing decision whenever a new build is published. Limiting no-range entries to code_not_in_use is a narrow temporary compromise: absence of the vulnerable code is generally more stable than reasons such as code_not_released, but package contents can still change in the future. All other not_applicable reasons continue to fall back to upstream.

We understand that the marker is package-wide and could hide a future finding if the package contents change. We will not merge the feed change until this limitation is agreed on. Is this narrow temporary use acceptable, or would you prefer that we publish no no-range entries until we have a lifecycle guarantee or use VEX?

Regards,
Laiza

@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

Hi Dmitriy,

After reviewing the lifecycle risk, we decided not to publish package-wide no-range entries for code_not_in_use. Since that decision is not guaranteed to remain true for every future Echo build, the marker could hide a real vulnerability later.

I closed the corresponding Platform PR and removed the no-range regression test and documentation from this Trivy PR. For now, these cases will continue to fall back to upstream, so we accept the known false positives and can consider version-scoped VEX separately.

The core of this PR is unchanged: fixed Echo advisories override matching upstream advisories, while unresolved and unrelated vulnerabilities continue to use upstream. go test ./pkg/detector/library/... passes after the removal.

This means the empty-range policy no longer needs to block this PR. Please review the remaining core change when your release work allows.

Regards,
Laiza

@DmitriyLewen

Copy link
Copy Markdown
Contributor

Hi Laiza,

I understand your decision about code_not_in_use and VEX files. I think it's the best approach in the current situation.

Now we need to settle the version comparison for Maven.
What I'm less sure about is how it's wired up right now: the driver gets an optional upstreamVersioner interface, and comparableAdvisory carries its own comparison version for each advisory.
This moves part of the Echo-specific logic into the shared driver code, and a supplier that returns MatchedWithUpstream but doesn't implement UpstreamVersion would silently fall back to comparing the full version.
I'd prefer not to extend the interface and the driver for this, if we can avoid it.

One option: a single comparer for all Echo ecosystems that decides how to compare by itself.
IsVulnerable receives the whole advisory, and the advisory already has DataSource, so the comparer can tell Echo records from upstream ones:

// echoComparer evaluates Echo and upstream advisories for an Echo package.
type echoComparer struct {
	eco     ecosystem.Type
	def     compare.Comparer // ecosystem comparer for upstream advisories
	special compare.Comparer // Echo comparer where "+echo.N" is significant
}

func (c echoComparer) IsVulnerable(ver string, adv dbTypes.Advisory) bool {
	if adv.DataSource != nil && adv.DataSource.ID == vulnerability.EchoOSV {
		return c.special.IsVulnerable(ver, adv)
	}
	if c.eco == ecosystem.Maven {
		// Maven orders X+echo.N above X, so upstream advisories use the base version.
		ver, _, _ = strings.Cut(ver, "+echo.")
	}
	// pip/npm/NuGet/Go ignore local versions / build metadata by themselves.
	return c.def.IsVulnerable(ver, adv)
}

Then Supplier.Comparer returns this comparer, and the driver only merges advisories by ID before the comparison and uses one comparer for the whole list.
upstreamVersioner, comparableAdvisory and the per-advisory version are no longer needed, and all the Echo version logic stays in the echo package.
We'd also need to decide (and cover with a test) what happens when DataSource is empty.

@knqyf263 what do you think about this approach?
Maybe you have other ideas on how to structure it?

Regards, Dmitriy

@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

Thanks, Dmitriy. Your approach makes sense to me. I’ll wait for @knqyf263’s feedback before updating the PR.

@knqyf263

Copy link
Copy Markdown
Collaborator

I like the idea of keeping the version comparison in echoComparer. I'm less sure the shared library driver should own the advisory merge, since suppliers may need different rules for which sources to query and which advisory takes precedence. Root.io already handles those decisions in its own getter. Root.io's VulnSrcGetter.Get

What do you think about replacing Supplier.BucketPrefix with Supplier.Advisories so each supplier can return the advisories it wants Trivy to evaluate? Echo would read both buckets and prefer its own advisory when the primary vulnerability IDs match. Seal would read its own bucket, with the existing fallback for an empty Candidate result. The driver would delegate the lookup to Advisories and use the comparer returned by Supplier.Comparer.

That also lets Echo return Matched and drop MatchedWithUpstream. Match can focus on identifying the supplier, and Advisories can decide what to look up.

diff --git a/pkg/detector/library/supplier.go b/pkg/detector/library/supplier.go
--- a/pkg/detector/library/supplier.go
+++ b/pkg/detector/library/supplier.go
@@ -25,8 +27,2 @@ const (
 	Candidate
-
-	// MatchedWithUpstream indicates the package definitely belongs to the
-	// supplier, but advisories from the default ecosystem bucket are also
-	// required. Supplier advisories override default advisories for the same
-	// primary vulnerability ID.
-	MatchedWithUpstream
 )
@@ -51,5 +42,6 @@ type Supplier interface {
 
-	// BucketPrefix returns the advisory bucket prefix for the given ecosystem.
-	// For example, "seal pip::" for Seal Security pip packages.
-	BucketPrefix(eco ecosystem.Type) string
+	// Advisories returns the advisories to evaluate for the matched package.
+	// pkgName is the normalized package name used for database lookups.
+	// A Candidate must return an empty list if supplier ownership cannot be confirmed.
+	Advisories(dbc db.Config, eco ecosystem.Type, pkgName string) ([]dbTypes.Advisory, error)
 
diff --git a/pkg/detector/library/echo/echo.go b/pkg/detector/library/echo/echo.go
--- a/pkg/detector/library/echo/echo.go
+++ b/pkg/detector/library/echo/echo.go
@@ -62 +66 @@ func (echoSupplier) Match(eco ecosystem.Type, _, pkgVer string) library.MatchRes
-			return library.MatchedWithUpstream
+			return library.Matched
@@ -70 +74 @@ func (echoSupplier) Match(eco ecosystem.Type, _, pkgVer string) library.MatchRes
-		return library.MatchedWithUpstream
+		return library.Matched
@@ -86,7 +89,26 @@ func (e echoSupplier) BucketPrefix(eco ecosystem.Type) string {
 
-// UpstreamVersion removes Echo's local/build metadata so upstream advisories
-// are evaluated against the upstream version from which the Echo build derives.
-func (echoSupplier) UpstreamVersion(pkgVer string) string {
-	upstreamVersion, _, _ := strings.Cut(pkgVer, "+echo.")
-	return upstreamVersion
+// Advisories combines upstream and Echo advisories, preferring Echo when the
+// primary vulnerability IDs match.
+func (e echoSupplier) Advisories(dbc db.Config, eco ecosystem.Type, pkgName string) ([]dbTypes.Advisory, error) {
+	echoAdvisories, err := dbc.GetAdvisories(e.bucketPrefix(eco), pkgName)
+	if err != nil {
+		return nil, err
+	}
+	upstreamAdvisories, err := dbc.GetAdvisories(string(eco)+"::", pkgName)
+	if err != nil {
+		return nil, fmt.Errorf("failed to get upstream advisories: %w", err)
+	}
+
+	echoIDs := set.New[string]()
+	for _, adv := range echoAdvisories {
+		echoIDs.Append(adv.VulnerabilityID)
+	}
+
+	merged := make([]dbTypes.Advisory, 0, len(upstreamAdvisories)+len(echoAdvisories))
+	for _, adv := range upstreamAdvisories {
+		if !echoIDs.Contains(adv.VulnerabilityID) {
+			merged = append(merged, adv)
+		}
+	}
+	return append(merged, echoAdvisories...), nil
 }
diff --git a/pkg/detector/library/seal/seal.go b/pkg/detector/library/seal/seal.go
--- a/pkg/detector/library/seal/seal.go
+++ b/pkg/detector/library/seal/seal.go
@@ -133,2 +134,7 @@ func (s sealSecurity) BucketPrefix(eco ecosystem.Type) string {
 
+// Advisories returns the advisories from the Seal Security bucket.
+func (s sealSecurity) Advisories(dbc db.Config, eco ecosystem.Type, pkgName string) ([]dbTypes.Advisory, error) {
+	return dbc.GetAdvisories(s.bucketPrefix(eco), pkgName)
+}
+
 // Comparer returns a version comparer for the given ecosystem.

@DmitriyLewen

DmitriyLewen commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks, @knqyf263. I like the idea of replacing BucketPrefix with Advisories.

When I was thinking about the new MatchedWithUpstream value, I also started from the idea of splitting responsibilities between Match and the driver.
But after thinking it over again, I came to the conclusion that MatchResult plus extra logic in the driver splits one and the same concern into two parts.

So I'd like to propose going one step further: if we move the advisory lookup into Advisories, should we also drop MatchResult and have Match return a bool?

Advisories moves the responsibility for choosing the advisory list to the supplier, which means each supplier decides on its own which advisories to take from the DB.
With Candidate kept in the driver (as in your proposal), the logic would be:

  • Echo merges advisories from its own bucket and the upstream bucket in Advisories, under its own rules.
  • Seal reads only its own bucket in Advisories, while the candidate logic stays in the shared driver. Yet it is essentially the same kind of decision as Echo's: Seal also chooses between its own and upstream advisories, just under its own conditions (the -spN/.0.1.spN suffix can also appear on real npm/Go/RubyGems packages). Keeping it in the shared code looks inconsistent.

My proposal (sketch below):

  • Match returns bool, and Advisories also gets the package version, so Seal can tell an authoritative match from a candidate. MatchResult and BucketPrefix are removed.
  • Comparer must handle every advisory returned by Advisories. For Echo, this is echoComparer, which picks the comparer based on DataSource.ID == vulnerability.EchoOSV (advisories with a nil DataSource are treated as upstream).

A sketch (simplified, error wrapping omitted; Echo.Advisories is the same as in your sketch, with an unused pkgVer):

// supplier.go
type Supplier interface {
	Name() string
	// Match reports whether a package may be provided by the supplier.
	Match(eco ecosystem.Type, pkgName, pkgVer string) bool
	// Advisories returns the advisories to evaluate for the matched package.
	Advisories(dbc db.Config, eco ecosystem.Type, pkgName, pkgVer string) ([]dbTypes.Advisory, error)
	// Comparer must handle every advisory returned by Advisories.
	Comparer(eco ecosystem.Type, defaultComparer compare.Comparer) compare.Comparer
}

// driver.go
func (d *Driver) advisories(pkgName, pkgVer string) ([]dbTypes.Advisory, compare.Comparer, error) {
	if v := lookupSupplier(d.ecosystem, pkgName, pkgVer); v != nil {
		advisories, err := v.Advisories(d.dbc, d.ecosystem, pkgName, pkgVer)
		return advisories, v.Comparer(d.ecosystem, d.comparer), err
	}
	advisories, err := d.dbc.GetAdvisories(DefaultBucketPrefix(d.ecosystem), pkgName)
	return advisories, d.comparer, err
}

// seal.go
func (sealSecurity) Match(eco ecosystem.Type, pkgName, pkgVer string) bool {
	return match(eco, pkgName, pkgVer) != noMatch // noMatch/matched/candidate are unexported now
}

func (s sealSecurity) Advisories(dbc db.Config, eco ecosystem.Type, pkgName, pkgVer string) ([]dbTypes.Advisory, error) {
	advisories, err := dbc.GetAdvisories(s.bucketPrefix(eco), pkgName)
	if err != nil || len(advisories) > 0 || match(eco, pkgName, pkgVer) != candidate {
		return advisories, err
	}
	// A candidate without Seal advisories is not a Seal package.
	return dbc.GetAdvisories(library.DefaultBucketPrefix(eco), pkgName)
}

However, this approach has one problem: Seal would have to decide what to do with candidates that are not actually its packages, and the Seal comparer is applied to them, which is safe today only because Seal returns the default comparer for npm, Go and RubyGems.
To address this, we could add another return value to Advisories that indicates whether the candidate was confirmed:

// supplier.go
// ok == false: the supplier could not confirm that it owns the package.
Advisories(dbc db.Config, eco ecosystem.Type, pkgName, pkgVer string) (advisories []dbTypes.Advisory, ok bool, err error)

// driver.go
func (d *Driver) advisories(pkgName, pkgVer string) ([]dbTypes.Advisory, compare.Comparer, error) {
	if v := lookupSupplier(d.ecosystem, pkgName, pkgVer); v != nil {
		advisories, ok, err := v.Advisories(d.dbc, d.ecosystem, pkgName, pkgVer)
		if err != nil || ok {
			return advisories, v.Comparer(d.ecosystem, d.comparer), err
		}
	}
	advisories, err := d.dbc.GetAdvisories(DefaultBucketPrefix(d.ecosystem), pkgName)
	return advisories, d.comparer, err
}

// seal.go (Echo always returns ok == true)
func (s sealSecurity) Advisories(dbc db.Config, eco ecosystem.Type, pkgName, pkgVer string) ([]dbTypes.Advisory, bool, error) {
	advisories, err := dbc.GetAdvisories(s.bucketPrefix(eco), pkgName)
	if err != nil {
		return nil, false, err
	}
	// A candidate without Seal advisories is not a Seal package.
	if len(advisories) == 0 && match(eco, pkgName, pkgVer) == candidate {
		return nil, false, nil
	}
	return advisories, true, nil
}

If Advisories returns false, the driver uses the default ecosystem advisories and the default comparer.
But this approach has its own downsides:

  • the flag can be interpreted in different ways (e.g. as "no advisories found");
  • the final decision on whether a package belongs to the supplier would be split between two places (Match + Advisories). That said, both places stay within the same supplier rather than being split between the supplier and the shared driver.

What do you think?

Co-authored-by: Cursor <cursoragent@cursor.com>
@LaizaAngrest

Copy link
Copy Markdown
Contributor Author

@knqyf263 @DmitriyLewen I implemented the Supplier.Advisories proposal while keeping the existing MatchResult/Candidate flow:

  • BucketPrefix and MatchedWithUpstream are removed.
  • Echo returns Matched; its Advisories method reads both buckets and lets the Echo advisory replace upstream only when the primary vulnerability IDs match.
  • Seal reads only its own bucket, and the shared driver keeps the existing empty-Candidate fallback to upstream.
  • echoComparer selects the Echo comparer only for DataSource.ID == vulnerability.EchoOSV; nil/unknown data sources use upstream behavior. Upstream Maven advisories are compared against the base version, while Echo Maven advisories keep the full version.
  • Added regression coverage for data-source selection and for definitive Seal matches not including upstream advisories.

The focused library tests, race tests, vet, and Trivy build pass. Could you please take another look?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants